home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGSCAL
/
TINYPASC.LZH
/
TURUN.LST
< prev
next >
Wrap
File List
|
1986-02-24
|
20KB
|
405 lines
TURUN.ASM 2/24/86
Page: 1 14:08:03
LOC OBJ LINE SOURCE CHASM version 4.03
0100 1 ; Tiny Pascal assembler code
0100 BC290B 2 MOV SP,OFFSET(STACKORG)
0103 8BEC 3 MOV BP,SP
0105 E81901 4 CALL MAIN
0108 CD20 5 INT 020H
010A 6 ; <STDIO.HDR> included
010A 7 ; STDIO.HDR
010A 8 ;
010A 9 ; READ and WRITE routines needed for Tiny Pascal
010A 10 ;
010A 11 SYS_RCHAR PROC NEAR ; Read single character from
010A B401 12 MOV AH,1
010C CD21 13 INT 021H
010E C3 14 RET ; value comes back in AL
010F 15 ENDP
010F 16
010F 17 SYS_WRCHAR PROC NEAR ; Write a single character (
010F B402 18 MOV AH,2
0111 CD21 19 INT 021H
0113 C3 20 RET
0114 21 ENDP
0114 22
0114 23 SYS_WHEX PROC NEAR ; Write a single HEX number
0114 80FA0A 24 CMP DL,10
0117 7C07 25 JL SYS_01
0119 80C237 26 ADD DL,55 ; 'A' - 10
011C E8F0FF 27 CALL SYS_WRCHAR
011F C3 28 RET
0120 80C230 29 SYS_01 ADD DL,'0'
0123 E8E9FF 30 CALL SYS_WRCHAR
0126 C3 31 RET
0127 32 ENDP
0127 33
0127 34 SYS_IWRT PROC NEAR ; Write an integer to stdout
0127 B604 35 MOV DH,4 ; used as a counter
0129 D1C0 36 SYS_11 ROL AX
012B D1C0 37 ROL AX
012D D1C0 38 ROL AX
012F D1C0 39 ROL AX
0131 8AD0 40 MOV DL,AL
0133 80E20F 41 AND DL,0FH
0136 50 42 PUSH AX
0137 E8DAFF 43 CALL SYS_WHEX
013A 58 44 POP AX
013B FECE 45 DEC DH
013D 75EA 46 JNZ SYS_11
013F C3 47 RET
0140 48 ENDP
0140 49
0140 50 SYS_SWRT PROC NEAR ; Write a string terminated
0140 8A5700 51 SYS_21 MOV DL,0[BX]
0143 80FA00 52 CMP DL,0
0146 7501 53 JNZ SYS_22 ; zero terminator?
0148 C3 54 RET
0149 E8C3FF 55 SYS_22 CALL SYS_WRCHAR
014C 43 56 INC BX
014D EBF1 57 JMPS SYS_21
014F 58 ENDP
014F 59
014F 60 SYS_WRTLN PROC NEAR ; write carriage return/lin
014F B20D 61 MOV DL,0DH
0151 E8BBFF 62 CALL SYS_WRCHAR
0154 B20A 63 MOV DL,0AH
0156 E8B6FF 64 CALL SYS_WRCHAR
0159 C3 65 RET
015A 66 ENDP
015A 67
015A 68 READ PROC NEAR ; read a HEX number fr
015A BA0000 69 MOV DX,0 ; clear DX
015D E8AAFF 70 READ_01 CALL SYS_RCHAR ; get one character in
0160 71 ; won't affect DX
0160 3C0D 72 CMP AL,0DH
0162 7506 73 JNZ READ_02
0164 52 74 PUSH DX ; save the thing we've
0165 E8E7FF 75 CALL SYS_WRTLN ; send a carriage retu
0168 58 76 POP AX ; was an ENTER
0169 C3 77 RET
016A 3C20 78 READ_02 CMP AL,' '
016C 74EF 79 JZ READ_01 ; ignore spaces
016E 2C30 80 SUB AL,'0' ; start conversion to
0170 3C09 81 CMP AL,9
0172 7E02 82 JLE READ_03
0174 2C07 83 SUB AL,7 ; turn 'A' into 0AH
0176 3C0F 84 READ_03 CMP AL,0FH
0178 7E02 85 JLE READ_04
017A 2C20 86 SUB AL,32 ; turn 'a' into 0AH
017C 240F 87 READ_04 AND AL,0FH ; clip for good measur
017E D1E2 88 SHL DX ; prepare DX for hex v
0180 D1E2 89 SHL DX
0182 D1E2 90 SHL DX
0184 D1E2 91 SHL DX
0186 08C2 92 OR DL,AL
0188 EBD3 93 JMPS READ_01 ; go do some more
018A 94 ENDP
018A 95
018A 96 READLN PROC NEAR
018A EBCE 97 JMPS READ ; does the same thing
018C 98 ENDP
018C 99
018C 100 ; ... end of include STDIO.HDR
018C 101 ; {TURUN -- A sample program written in Tiny Pascal
018C 102 ; var I, J, K, PROBLEM;
018C 103 ;
018C 104 ; {*********************}
018C 105 ; function ISLESS(N1, N2);
018C 106 ; begin {returns 1 if n1<n2, 0 otherwise}
018C 107 ; if n2-n1 then isless:=1 {truth value test is
018C 108 ; else isless:=0;
018C 109 ; end;
018C 110 ISLESS PROC NEAR
018C 55 111 PUSH BP
018D 8BEC 112 MOV BP,SP
018F 8B4604 113 MOV AX,4[BP] ; N2
0192 2B4606 114 SUB AX,6[BP] ; N1
0195 3D0000 115 CMP AX,0
0198 7E08 116 JLE XXX0
019A C746080100 117 MOVW 8[BP],1 ; ISLESS
**** Diagnostic: Could use JMPS
019F E90500 118 JMP XXX1
01A2 119 XXX0 EQU $
01A2 C746080000 120 MOVW 8[BP],0 ; ISLESS
01A7 121 XXX1 EQU $
01A7 8B4608 122 MOV AX,8[BP] ; ISLESS
01AA 5D 123 POP BP
01AB C20600 124 RET 6
01AE 125 ENDP
01AE 126 ; SYMBOL TABLE
01AE 127 ; ISLESS 8[BP]
01AE 128 ; N1 6[BP]
01AE 129 ; N2 4[BP]
01AE 130
01AE 131 ;
01AE 132 ; function ADDEMUP(LOWER, UPPER, SUM);
01AE 133 ; begin end; {makes it a forward declaration}
01AE 134 ;
01AE 135 ; {*********************}
01AE 136 ; function ISEQUAL(N1, N2);
01AE 137 ; begin
01AE 138 ; if n2-n1 then isequal:=0 {false}
01AE 139 ; else
01AE 140 ; if n1-n2 then isequal:=0
01AE 141 ; else isequal:=1;
01AE 142 ; end;
01AE 143 ISEQUAL PROC NEAR
01AE 55 144 PUSH BP
01AF 8BEC 145 MOV BP,SP
01B1 8B4604 146 MOV AX,4[BP] ; N2
01B4 2B4606 147 SUB AX,6[BP] ; N1
01B7 3D0000 148 CMP AX,0
01BA 7E08 149 JLE XXX2
01BC C746080000 150 MOVW 8[BP],0 ; ISEQUAL
**** Diagnostic: Could use JMPS
01C1 E91800 151 JMP XXX3
01C4 152 XXX2 EQU $
01C4 8B4606 153 MOV AX,6[BP] ; N1
01C7 2B4604 154 SUB AX,4[BP] ; N2
01CA 3D0000 155 CMP AX,0
01CD 7E08 156 JLE XXX4
01CF C746080000 157 MOVW 8[BP],0 ; ISEQUAL
**** Diagnostic: Could use JMPS
01D4 E90500 158 JMP XXX5
01D7 159 XXX4 EQU $
01D7 C746080100 160 MOVW 8[BP],1 ; ISEQUAL
01DC 161 XXX5 EQU $
01DC 162 XXX3 EQU $
01DC 8B4608 163 MOV AX,8[BP] ; ISEQUAL
01DF 5D 164 POP BP
01E0 C20600 165 RET 6
01E3 166 ENDP
01E3 167 ; SYMBOL TABLE
01E3 168 ; ISEQUAL 8[BP]
01E3 169 ; N1 6[BP]
01E3 170 ; N2 4[BP]
01E3 171
01E3 172 ;
01E3 173 ; {***********************}
01E3 174 ; function ADDEMUP(LOWER, UPPER, SUM);
01E3 175 ; {SUM is a local}
01E3 176 ; begin
01E3 177 ; sum:=0;
01E3 178 ; while isless(lower, upper) do begin
01E3 179 ; sum:=sum+lower;
01E3 180 ; lower:=lower+1;
01E3 181 ; end;
01E3 182 ; addemup:=sum+lower; { the last one was left ou
01E3 183 ; end;
01E3 184 ADDEMUP PROC NEAR
01E3 55 185 PUSH BP
01E4 8BEC 186 MOV BP,SP
01E6 C746040000 187 MOVW 4[BP],0 ; SUM
01EB 188 XXX6 EQU $
01EB 50 189 PUSH AX
01EC 8B4608 190 MOV AX,8[BP] ; LOWER
01EF 50 191 PUSH AX
01F0 8B4606 192 MOV AX,6[BP] ; UPPER
01F3 50 193 PUSH AX
01F4 E895FF 194 CALL ISLESS
01F7 3D0000 195 CMP AX,0
01FA 7E15 196 JLE XXX7
01FC 8B4604 197 MOV AX,4[BP] ; SUM
01FF 034608 198 ADD AX,8[BP] ; LOWER
0202 894604 199 MOV 4[BP],AX ; SUM
0205 8B4608 200 MOV AX,8[BP] ; LOWER
0208 050100 201 ADD AX,1
020B 894608 202 MOV 8[BP],AX ; LOWER
**** Diagnostic: Could use JMPS
020E E9DAFF 203 JMP XXX6
0211 204 XXX7 EQU $
0211 8B4604 205 MOV AX,4[BP] ; SUM
0214 034608 206 ADD AX,8[BP] ; LOWER
0217 89460A 207 MOV 10[BP],AX ; ADDEMUP
021A 8B460A 208 MOV AX,10[BP] ; ADDEMUP
021D 5D 209 POP BP
021E C20800 210 RET 8
0221 211 ENDP
0221 212 ; SYMBOL TABLE
0221 213 ; ADDEMUP 10[BP]
0221 214 ; LOWER 8[BP]
0221 215 ; UPPER 6[BP]
0221 216 ; SUM 4[BP]
0221 217
0221 218 ;
0221 219 ; {*********************}
0221 220 ; function MAIN(SUM, UPPER);
0221 221 ; begin
0221 222 ; i:=1;
0221 223 ; j:=i+5;
0221 224 ; k:=j-16;
0221 225 ; problem:=i+(j*k);
0221 226 ; writeln('I: ', i, ' J: ', j, ' K: ', k, ' Probl
0221 227 ; write('Enter upper ');
0221 228 ; upper:=read;
0221 229 ; sum:=addemup(1, upper); {sum of integers 1..up
0221 230 ; if isequal(sum, (upper*(upper+1))/2) then
0221 231 ; writeln('Sum = ', sum)
0221 232 ; else begin
0221 233 ; writeln('BUG: Sum = ', sum, '; should be ',
0221 234 ; (upper*(upper+1))/2);
0221 235 ; end;
0221 236 ; end;
0221 237 MAIN PROC NEAR
0221 55 238 PUSH BP
0222 8BEC 239 MOV BP,SP
0224 C70653030100 240 MOVW I,1 ; I
022A A15303 241 MOV AX,I ; I
022D 050500 242 ADD AX,5
0230 A35503 243 MOV J,AX ; J
0233 A15503 244 MOV AX,J ; J
0236 2D1000 245 SUB AX,16
0239 A35703 246 MOV K,AX ; K
023C A15703 247 MOV AX,K ; K
023F 50 248 PUSH AX
0240 A15503 249 MOV AX,J ; J
0243 59 250 POP CX
0244 F7E9 251 IMULW CX
0246 50 252 PUSH AX
0247 A15303 253 MOV AX,I ; I
024A 5A 254 POP DX
024B 01D0 255 ADD AX,DX
024D A35103 256 MOV PROBLEM,AX ; PROBLEM
0250 BB4D03 257 MOV BX,OFFSET(SS0)
0253 E8EAFE 258 CALL SYS_SWRT
0256 A15303 259 MOV AX,I ; I
0259 E8CBFE 260 CALL SYS_IWRT
025C BB4803 261 MOV BX,OFFSET(SS1)
025F E8DEFE 262 CALL SYS_SWRT
0262 A15503 263 MOV AX,J ; J
0265 E8BFFE 264 CALL SYS_IWRT
0268 BB4303 265 MOV BX,OFFSET(SS2)
026B E8D2FE 266 CALL SYS_SWRT
026E A15703 267 MOV AX,K ; K
0271 E8B3FE 268 CALL SYS_IWRT
0274 BB3803 269 MOV BX,OFFSET(SS3)
0277 E8C6FE 270 CALL SYS_SWRT
027A A15103 271 MOV AX,PROBLEM ; PROBLEM
027D E8A7FE 272 CALL SYS_IWRT
0280 E8CCFE 273 CALL SYS_WRTLN
0283 BB2B03 274 MOV BX,OFFSET(SS4)
0286 E8B7FE 275 CALL SYS_SWRT
0289 E8CEFE 276 CALL READ
028C 894604 277 MOV 4[BP],AX ; UPPER
028F 50 278 PUSH AX
0290 B80100 279 MOV AX,1
0293 50 280 PUSH AX
0294 8B4604 281 MOV AX,4[BP] ; UPPER
0297 50 282 PUSH AX
0298 B80000 283 MOV AX,0
029B 50 284 PUSH AX
029C E844FF 285 CALL ADDEMUP
029F 894606 286 MOV 6[BP],AX ; SUM
02A2 50 287 PUSH AX
02A3 8B4606 288 MOV AX,6[BP] ; SUM
02A6 50 289 PUSH AX
02A7 B80200 290 MOV AX,2
02AA 50 291 PUSH AX
02AB 8B4604 292 MOV AX,4[BP] ; UPPER
02AE 050100 293 ADD AX,1
02B1 50 294 PUSH AX
02B2 8B4604 295 MOV AX,4[BP] ; UPPER
02B5 59 296 POP CX
02B6 F7E9 297 IMULW CX
02B8 99 298 CWD
02B9 59 299 POP CX
02BA F7F9 300 IDIVW CX
02BC 50 301 PUSH AX
02BD E8EEFE 302 CALL ISEQUAL
02C0 3D0000 303 CMP AX,0
02C3 7E12 304 JLE XXX8
02C5 BB2403 305 MOV BX,OFFSET(SS5)
02C8 E875FE 306 CALL SYS_SWRT
02CB 8B4606 307 MOV AX,6[BP] ; SUM
02CE E856FE 308 CALL SYS_IWRT
02D1 E87BFE 309 CALL SYS_WRTLN
**** Diagnostic: Could use JMPS
02D4 E92D00 310 JMP XXX9
02D7 311 XXX8 EQU $
02D7 BB1803 312 MOV BX,OFFSET(SS6)
02DA E863FE 313 CALL SYS_SWRT
02DD 8B4606 314 MOV AX,6[BP] ; SUM
02E0 E844FE 315 CALL SYS_IWRT
02E3 BB0B03 316 MOV BX,OFFSET(SS7)
02E6 E857FE 317 CALL SYS_SWRT
02E9 B80200 318 MOV AX,2
02EC 50 319 PUSH AX
02ED 8B4604 320 MOV AX,4[BP] ; UPPER
02F0 050100 321 ADD AX,1
02F3 50 322 PUSH AX
02F4 8B4604 323 MOV AX,4[BP] ; UPPER
02F7 59 324 POP CX
02F8 F7E9 325 IMULW CX
02FA 99 326 CWD
02FB 59 327 POP CX
02FC F7F9 328 IDIVW CX
02FE E826FE 329 CALL SYS_IWRT
0301 E84BFE 330 CALL SYS_WRTLN
0304 331 XXX9 EQU $
0304 8B4608 332 MOV AX,8[BP] ; MAIN
0307 5D 333 POP BP
0308 C20600 334 RET 6
030B 3B2073686F75 335 SS7 DB '; should be ',0
6C6420626520
00
0318 4255473A2053 336 SS6 DB 'BUG: Sum = ',0
756D203D2000
0324 53756D203D20 337 SS5 DB 'Sum = ',0
00
032B 456E74657220 338 SS4 DB 'Enter upper ',0
757070657220
00
0338 2050726F626C 339 SS3 DB ' Problem: ',0
656D3A2000
0343 204B3A2000 340 SS2 DB ' K: ',0
0348 204A3A2000 341 SS1 DB ' J: ',0
034D 493A2000 342 SS0 DB 'I: ',0
0351 343 ENDP
0351 344 ; SYMBOL TABLE
0351 345 ; MAIN 8[BP]
0351 346 ; SUM 6[BP]
0351 347 ; UPPER 4[BP]
0351 348
0351 349 ;
0351 350 ; GLOBAL VARIABLES
0351 0000 351 PROBLEM DW 0
0353 0000 352 I DW 0
0355 0000 353 J DW 0
0357 0000 354 K DW 0
0359 355 ; RUNTIME STACK
0359 356 DS 2000
0B29 0000 357 STACKORG DW 0
0B2B 358 ; MAIN stack space
0B2B 0000 359 DW 0
0B2D 0000 360 DW 0
0B2F 0000 361 DW 0
0B31 362 ; NO errors
0 Error(s) detected
5 Diagnostic(s) offered
817 (331H) Bytes of object code generated
Symbol Table Dump:
ADDEMUP.........P01E3 I...............M0353 ISEQUAL.........P01AE
ISLESS..........P018C J...............M0355 K...............M0357
MAIN............P0221 PROBLEM.........M0351 READ............P015A
READLN..........P018A READ_01.........P015D READ_02.........P016A
READ_03.........P0176 READ_04.........P017C SS0.............M034D
SS1.............M0348 SS2.............M0343 SS3.............M0338
SS4.............M032B SS5.............M0324 SS6.............M0318
SS7.............M030B STACKORG........M0B29 SYS_01..........P0120
SYS_11..........P0129 SYS_21..........P0140 SYS_22..........P0149
SYS_IWRT........P0127 SYS_RCHAR.......P010A SYS_SWRT........P0140
SYS_WHEX........P0114 SYS_WRCHAR......P010F SYS_WRTLN.......P014F
XXX0............P01A2 XXX1............P01A7 XXX2............P01C4
XXX3............P01DC XXX4............P01D7 XXX5............P01DC
XXX6............P01EB XXX7............P0211 XXX8............P02D7
XXX9............P0304